#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;

	int a = 0, b = 1, c = 1;
	while (b < n)
	{
		a = b;
		int t = c;
		c = b + c;
		b = t;
	}
	cout << min(abs(n - b), min(abs(n - c), abs(n - a)));
	return 0;
}
